package chpt_06_04_template;

/**
 * @author Ping
 * @date 2023/5/25 9:29
 **/
public class TemplateDemo {
    public static void main(String args[]) {

        System.out.println("Student for lunch: ") ;
        CampusPerson stu = new Student() ;
        stu.forLunch();
        System.out.println("Teacher for lunch: ") ;
        CampusPerson teacher = new Teacher() ;
        teacher.forLunch();



    }
}

abstract class CampusPerson {

    public  void forLunch() {
        joinInLine();
        makeChoice();
        if (isBirthday()) {
            getADrinking();
        }
        pay();
        enjoyMeal();
    }
    public void getADrinking() {
        System.out.println("get a happy beverage.") ;
    }

    public void joinInLine() {

        System.out.println("join in line") ;
    }
    public void makeChoice() {
        System.out.println("choose meal.") ;
    }

    public void enjoyMeal() {
        System.out.println("enjoy the meal.") ;
    }
    public abstract void pay() ;
    public abstract boolean isBirthday() ;

}

class Student extends CampusPerson {


    @Override
    public void pay() {
        System.out.println("pay the  meal by WEI_XIN.") ;
    }

    @Override
    public boolean isBirthday() {
        return true ;
    }
}

class Teacher extends CampusPerson {
    @Override
    public void pay() {
        System.out.println("pay the  meal by CAMPUS_CARD.") ;
    }

    @Override
    public boolean isBirthday() {
        return false;
    }
}
